﻿@model ECG.WebUI.Models.ConfigFilterModel
@using ECG.Common
@{
    //Price
    var modelFil = (CategoryFilterModel)ViewBag.modelFil; // Khoang gia tu tieu chi loc
    var pMinDefault = new PriceFilterDto { Price = 0 };
    var pMaxDefault = new PriceFilterDto { Price = 0 };
    //Rate
    var listRate = (List<ECG.Common.RateFilterDto>)ViewBag.RateFil;
    var RateMinDefault = new RateFilterDto { AverageRate = 1, Total = 0 };
    var RateMaxDefault = new RateFilterDto { AverageRate = 5, Total = 0 };
}
<input type="hidden" name="urlPrice" id="urlPrice" value="@pMinDefault.Price.ToString("##,###").Replace(".", "");@pMaxDefault.Price.ToString("##,###").Replace(".", "")" />
<input type="hidden" name="urlRate" id="urlRate" value="@RateMinDefault.AverageRate;@RateMaxDefault.AverageRate" />

<div class="filterBox">
    <input type="hidden" name="hidCategoryId" value="@modelFil.CategoryId" />
    <!--PRICE RANGE-->
    @{
        if (Model.activePricRange)
        {
            if (Model.applyTypePriceRange.Equals("0") || Model.applyTypePriceRange.Equals("2") || Model.applyTypePriceRange.Equals("4"))
            {
                var arrCate = Model.CategoriesPriceRange.Split(';');
                var chk = -1;
                if (arrCate != null && arrCate.Length > 0)
                {
                    chk = Array.IndexOf(arrCate, modelFil.CategoryId);
                }
                // kiem tra xem danh muc hien tai dc cho phep hien thi hay ko
                if (chk > -1)
                {
                    var listPrice = (List<PriceFilterDto>)ViewBag.PriceFil ?? new List<PriceFilterDto>();
                    var listPriceDefault = (List<PriceFilterDto>)ViewBag.PriceFilDefault; // khoang gia mac dinh
                    pMinDefault = listPriceDefault.FirstOrDefault() ?? new PriceFilterDto { Price = 0 };
                    pMaxDefault = listPriceDefault.OrderByDescending(p => p.Price).FirstOrDefault() ?? new PriceFilterDto { Price = 0 };
                    var pMin = listPrice.FirstOrDefault() ?? new PriceFilterDto { Price = 0 };
                    var pMax = listPrice.OrderByDescending(p => p.Price).FirstOrDefault() ?? new PriceFilterDto { Price = 0 };
                    //var dataPrice = ViewBag.RateFilMap;
                    <div class="filter-header">
                        Giá
                        @if (pMinDefault.Price != pMin.Price || pMaxDefault.Price != pMax.Price)
                        {
                            <a href="javascript:void(0)" onclick="removeUrlPrice();">xóa</a>
                        }
                    </div>
                    <div class="filter-body">
                        <div id="ecg-slider"></div>
                        <div class="PriceRangeFil" style="padding-top:6px;">
                            <input type="text" id="priceMin" value="" />
                            <input type="text" id="priceMax" value="" />
                            <input type="hidden" id="hidpriceMin" value="" />
                            <input type="hidden" id="hidpriceMax" value="" />
                            @*<input type="button" id="btnFil" value="OK" class="btnFil"/>*@
                            @{
                        var priceMin = "";
                        var priceMax = "";
                        // neu khong co tham so
                        if (pMin != null && pMax != null)
                        {
                            priceMin = pMin.Price.ToString("##,###").Replace(".", "");
                            priceMax = pMax.Price.ToString("##,###").Replace(".", "");
                        }
                            }
                            <input type="hidden" name="hidPriceRang" value="@priceMin;@priceMax;@priceMin;@priceMax;@Model.rangeNumber" />
                        </div>
                    </div>
                }
            }
        }
    }

    @{
        if (Model.activeProvider)
        {
            if (Model.applyTypeProvider.Equals("0") || Model.applyTypeProvider.Equals("2") || Model.applyTypeProvider.Equals("4"))
            {
                var arrCate = Model.CategoriesProvider.Split(';');

                var chk = -1;
                if (arrCate != null && arrCate.Length > 0)
                {
                    chk = Array.IndexOf(arrCate, modelFil.CategoryId);
                }
                // kiem tra xem danh muc hien tai dc cho phep hien thi hay ko
                if (chk > -1)
                {
                    var listProvider = (List<ProviderFilterDto>)ViewBag.ProviderFil;

            <!--PROVIDER-->
                    <div class="filter-header">
                        Thương hiệu
                        @if (!string.IsNullOrEmpty(modelFil.Providers))
                        {
                            <a href="javascript:void(0)" onclick="removeUrlProvider()">xóa tất cả</a>
                        }
                    </div>
                    <div class="filter-body">
                        <div class="border-search-pro">
                            <input type="text" id="ProviderSearch" value="" placeholder="Tìm theo thương hiệu">
                            <input type="button" id="btnSearchProvider" value="OK">
                            <input type="hidden" value="@Model.showNumberLineProvider" name="hidHeightProvider" />
                        </div>
                        @if (listProvider.Any())
                        {
                            <div class="ListProviderFil">
                                <ul class="ul clearfix">
                                    @foreach (var item in listProvider)
                                    {
                                        var chkPram = "";
                                        // tham so nguoi dung chon tren url
                                        var chkParam = modelFil.Providers.Split(',');
                                        var paramchk = chkParam.Where(p => p.Equals(item.Id.ToString())).FirstOrDefault();
                                        if (!string.IsNullOrEmpty(paramchk))
                                        {
                                            chkPram = "checked='checked'";
                                        }
                                        <li>
                                            <input type="checkbox" @string.Format("{0}", chkPram) value="@item.Id" name="chkFilProvider" id="chkFilProvider-@item.Id" idata="@item.Id" />
                                            <a href="javascript:void(0)" title="@item.Name" rel="nofollow">
                                                <label for="chkFilProvider-@item.Id" style="cursor:pointer;">@item.Name (@item.Total)</label>
                                            </a>
                                        </li>
                                    }
                                </ul>

                            </div>
                        }
                    </div>
                }
            }
        }
    }

    @{
        if (Model.activeRate)
        {
            if (Model.applyTypeRate.Equals("0") || Model.applyTypeRate.Equals("2") || Model.applyTypeRate.Equals("4"))
            {
                var arrCate = Model.CategoriesRate.Split(';');

                var chk = -1;
                if (arrCate != null && arrCate.Length > 0)
                {
                    chk = Array.IndexOf(arrCate, modelFil.CategoryId);
                }
                // kiem tra xem danh muc hien tai dc cho phep hien thi hay ko
                if (chk > -1)
                {
                    var listRateDefault = (List<ECG.Common.RateFilterDto>)ViewBag.RateFilDefault;
                    var RateMin = new RateFilterDto { AverageRate = 1, Total = 0 };
                    var RateMax = new RateFilterDto { AverageRate = 5, Total = 0 };
                    if (listRateDefault.Any())
                    {
                        RateMinDefault = listRateDefault.FirstOrDefault();
                        RateMaxDefault = listRateDefault.OrderByDescending(r => r.AverageRate).FirstOrDefault();
                    }
                    if (listRate.Any())
                    {
                        RateMin = listRate.FirstOrDefault();
                        RateMax = listRate.OrderByDescending(r => r.AverageRate).FirstOrDefault();
                        if (RateMin.AverageRate <= 0)
                        {
                            RateMin.AverageRate = RateMinDefault.AverageRate <= 0 ? 1 : RateMinDefault.AverageRate;
                        }
                        if (RateMax.AverageRate <= 0)
                        {
                            RateMax.AverageRate = RateMaxDefault.AverageRate <= 0 ? 5 : RateMaxDefault.AverageRate; ;
                        }
                    }


            <!--RATE-->
                    <div class="filter-header">
                        Đánh giá
                        @if (RateMinDefault.AverageRate != RateMin.AverageRate || RateMaxDefault.AverageRate != RateMax.AverageRate)
                        {
                            <a href="javascript:void(0)" onclick="removeUrlRate()">xóa</a>
                        }
                    </div>
                    <div class="filter-body clearfix" id="plcRateRil">
                        <div class="Rate-fil fl">
                            <div id="ecg-slider-rate"></div>
                            <input type="hidden" id="rateValueMin" value="1">
                            <input type="hidden" id="rateValueMax" value="5">
                            <input type="hidden" name="hidRateRil" value="@RateMin.AverageRate.ToString();@RateMax.AverageRate.ToString()" />
                        </div>
                        <div class="listStarFil fl">
                            <ul class="ul">
                                @for (int i = 1; i <= 5; i++)
                                {
                                    var w = 120 - (i * 20);
                                    var starNone = "starNone";
                                    var starTotal = 0;
                                    
                                    for (int j = Convert.ToInt32(RateMin.AverageRate); j <= Convert.ToInt32(RateMax.AverageRate); j++)
                                    {
                                        if (w / 20 == j)
                                        {
                                            starNone = "";
                                            var item = listRate.Where(r => r.AverageRate == j).FirstOrDefault();
                                            if (item != null)
                                            {
                                                starTotal = item.Total;
                                            }

                                            break;
                                        }
                                    }
                                    <li>
                                        @Html.Raw(string.Format("{0}", (i > 1 && i < 5) ? "<i class='line-fil-rate'></i>" : ""))
                                        <div style="line-height: 13px;">
                                            <span class="@string.Format("{0}",i==1?"itm-ratStars":"") inlineBlocka" style="position:relative;">
                                                <span style="width: @w%;" class="itm-ratStars itm-ratRating @starNone"></span>
                                                <span class="totalRate">(@starTotal)</span>
                                            </span>
                                        </div>
                                    </li>
                                }

                                @*<li>
                                        <i class="line-fil-rate"></i>
                                        <div style="line-height: 13px;">
                                            <span class="inlineBlocka"><span style="width: 80%;" class="itm-ratStars itm-ratRating"></span></span>
                                        </div>
                                    </li>
                                    <li>
                                        <i class="line-fil-rate"></i>
                                        <div style="line-height: 13px;">
                                            <span class="inlineBlocka"><span style="width: 60%;" class="itm-ratStars itm-ratRating"></span></span>
                                        </div>
                                    </li>
                                    <li>
                                        <i class="line-fil-rate"></i>
                                        <div style="line-height: 13px;">
                                            <span class="inlineBlocka"><span style="width: 40%;" class="itm-ratStars itm-ratRating"></span></span>
                                        </div>
                                    </li>
                                    <li>
                                        <div style="line-height: 13px;">
                                            <span class="inlineBlocka"><span style="width: 20%;" class="itm-ratStars itm-ratRating"></span></span>
                                        </div>
                                    </li>*@
                            </ul>
                        </div>
                    </div>

                }
            }
        }
    }

    @{
        if (Model.activeColor)
        {
            if (Model.applyTypeColor.Equals("0") || Model.applyTypeColor.Equals("2") || Model.applyTypeColor.Equals("4"))
            {
                var arrCate = Model.CategoriesColor.Split(';');

                var chk = -1;
                if (arrCate != null && arrCate.Length > 0)
                {
                    chk = Array.IndexOf(arrCate, modelFil.CategoryId);
                }
                // kiem tra xem danh muc hien tai dc cho phep hien thi hay ko
                if (chk > -1)
                {
                    var listColor = (List<ECG.Common.ColorFilterDto>)ViewBag.ColorFil;
            <!--COLOR-->

                    <div class="filter-header">
                        Mầu sắc
                        @if (!string.IsNullOrEmpty(modelFil.Colors))
                        {
                            <a href="javascript:void(0)" onclick="removeUrlColor()">xóa tất cả</a>
                        }
                    </div>
                    <div class="filter-body">
                        <div class="ColorFil">
                            <input type="hidden" value="@Model.showNumberLineColor" name="hidHeightColor" />
                            @if (listColor.Any())
                            {
                                <ul class="ul clearfix">
                                    @foreach (var item in listColor)
                                    {
                                        var chkPram = "";
                                        // tham so nguoi dung chon tren url
                                        var chkParam = modelFil.Colors.Split(',');
                                        var paramchk = chkParam.Where(p => p.Equals(item.Id.ToString())).FirstOrDefault();
                                        if (!string.IsNullOrEmpty(paramchk))
                                        {
                                            chkPram = "checked='checked'";
                                        }
                                        <li>
                                            <input type="checkbox" @chkPram value="@item.Id" name="chkFilColor" id="chkFilColor-@item.Id" idata="@item.Id" />
                                            <label for="chkFilColor-@item.Id" title="@item.Name">@item.Name (@item.Total)</label>
                                        </li>
                                    }
                                </ul>
                            }
                        </div>
                    </div>

                }
            }
        }
    }

    @{
        if (Model.activeSize)
        {
            if (Model.applyTypeSize.Equals("0") || Model.applyTypeSize.Equals("2") || Model.applyTypeSize.Equals("4"))
            {
                var arrCate = Model.CategoriesSize.Split(';');

                var chk = -1;
                if (arrCate != null && arrCate.Length > 0)
                {
                    chk = Array.IndexOf(arrCate, modelFil.CategoryId);
                }
                // kiem tra xem danh muc hien tai dc cho phep hien thi hay ko
                if (chk > -1)
                {
                    var listSize = (List<ECG.Common.SizeFilterDto>)ViewBag.SizeFil;
            <!--SIZE-->

                    <div class="filter-header">
                        Kích thước
                        @if (!string.IsNullOrEmpty(modelFil.Sizes))
                        {
                            <a href="javascript:void(0)" onclick="removeUrlSize()">xóa tất cả</a>
                        }
                    </div>
                    <div class="filter-body">
                        <div class="SizeFil">
                            <input type="hidden" value="@Model.showNumberLineSize" name="hidHeightSize" />
                            @if (listSize.Any())
                            {
                                <ul class="ul clearfix">
                                    @foreach (var item in listSize)
                                    {
                                        var chkPram = "";
                                        // tham so nguoi dung chon tren url
                                        var chkParam = modelFil.Sizes.Split(',');
                                        var paramchk = chkParam.Where(p => p.Equals(item.Id.ToString())).FirstOrDefault();
                                        if (!string.IsNullOrEmpty(paramchk))
                                        {
                                            chkPram = "checked='checked'";
                                        }
                                        <li>
                                            <input type="checkbox" @chkPram value="@item.Id" name="chkFilSize" id="chkFilSize-@item.Id" idata="@item.Id" />
                                            <label for="chkFilSize-@item.Id" title="@item.SizeName">@item.SizeName (@item.Total)</label>
                                        </li>
                                    }
                                </ul>
                            }
                        </div>
                    </div>

                }
            }
        }
    }

    @{
        if (Model.activeAttr)
        {
            if (Model.applyTypeAttr.Equals("0") || Model.applyTypeAttr.Equals("2") || Model.applyTypeAttr.Equals("4"))
            {
                var arrCate = Model.CategoriesAttr.Split(';');

                var chk = -1;
                if (arrCate != null && arrCate.Length > 0)
                {
                    chk = Array.IndexOf(arrCate, modelFil.CategoryId);
                }
                // kiem tra xem danh muc hien tai dc cho phep hien thi hay ko
                if (chk > -1)
                {
                    var listAttr = (List<ECG.Common.AttrFilterDto>)ViewBag.AttrFil;
            <!--ATTRIBUTE-->

                    <div class="filter-header">
                        Thuộc tính khác
                        @if (!string.IsNullOrEmpty(modelFil.Attrs))
                        {
                            <a href="javascript:void(0)" onclick="removeUrlAttr()">xóa tất cả</a>
                        }
                    </div>
                    <div class="filter-body">
                        <div class="AttrFil">
                            <input type="hidden" value="@Model.showNumberLineAttr" name="hidHeightAttr" />
                            @if (listAttr.Any())
                            {
                                <ul class="ul clearfix">
                                    @foreach (var item in listAttr)
                                    {
                                        var chkPram = "";
                                        // tham so nguoi dung chon tren url
                                        var chkParam = modelFil.Attrs.Split(',');
                                        var paramchk = chkParam.Where(p => p.Equals(item.Id.ToString())).FirstOrDefault();
                                        if (!string.IsNullOrEmpty(paramchk))
                                        {
                                            chkPram = "checked='checked'";
                                        }
                                        <li>
                                            <input type="checkbox" @chkPram value="@item.Id" name="chkFilAttr" id="chkFilAttr-@item.Id" idata="@item.Id" />
                                            <label for="chkFilAttr-@item.Id" title="@item.AttributeName">@item.AttributeName (@item.Total)</label>
                                        </li>
                                    }
                                </ul>
                            }
                        </div>
                    </div>
                }
            }
        }
    }

</div>
